<?php

namespace App\Http\Controllers\Backend;

use App\DataTables\ChannelRelayDayDataTable;
use App\Http\Requests;
use App\Http\Requests\CreateChannelRelayDayRequest;
use App\Http\Requests\UpdateChannelRelayDayRequest;
use App\Repositories\ChannelRelayDayRepository;
use Flash;
use App\Http\Controllers\AppBaseController;
use Response;

class ChannelRelayDayController extends AppBaseController
{
    /** @var  ChannelRelayDayRepository */
    private $channelRelayDayRepository;

    public function __construct(ChannelRelayDayRepository $channelRelayDayRepo)
    {
        $this->channelRelayDayRepository = $channelRelayDayRepo;
    }

    /**
     * Display a listing of the ChannelRelayDay.
     *
     * @param ChannelRelayDayDataTable $channelRelayDayDataTable
     * @return Response
     */
    public function index(ChannelRelayDayDataTable $channelRelayDayDataTable)
    {
        return $channelRelayDayDataTable->render('backend.channel_relay_days.index');
    }

    /**
     * Show the form for creating a new ChannelRelayDay.
     *
     * @return Response
     */
    public function create()
    {
        return view('backend.channel_relay_days.create');
    }

    /**
     * Store a newly created ChannelRelayDay in storage.
     *
     * @param CreateChannelRelayDayRequest $request
     *
     * @return Response
     */
    public function store(CreateChannelRelayDayRequest $request)
    {
        $input = $request->all();

        $channelRelayDay = $this->channelRelayDayRepository->create($input);

        Flash::success(trans('flash.controller.save_success', ['model' => 'Channel Relay Day']));

        return redirect(route('channelRelayDays.index'));
    }

    /**
     * Display the specified ChannelRelayDay.
     *
     * @param  int $id
     *
     * @return Response
     */
    public function show($id)
    {
        $channelRelayDay = $this->channelRelayDayRepository->findWithoutFail($id);

        if (empty($channelRelayDay)) {
            Flash::error(trans('flash.controller.not_found', ['model' => 'Channel Relay Day']));

            return redirect(route('channelRelayDays.index'));
        }

        return view('backend.channel_relay_days.show')->with('channelRelayDay', $channelRelayDay);
    }

    /**
     * Show the form for editing the specified ChannelRelayDay.
     *
     * @param  int $id
     *
     * @return Response
     */
    public function edit($id)
    {
        $channelRelayDay = $this->channelRelayDayRepository->findWithoutFail($id);

        if (empty($channelRelayDay)) {
            Flash::error(trans('flash.controller.not_found', ['model' => 'Channel Relay Day']));

            return redirect(route('channelRelayDays.index'));
        }

        return view('backend.channel_relay_days.edit')->with('channelRelayDay', $channelRelayDay);
    }

    /**
     * Update the specified ChannelRelayDay in storage.
     *
     * @param  int              $id
     * @param UpdateChannelRelayDayRequest $request
     *
     * @return Response
     */
    public function update($id, UpdateChannelRelayDayRequest $request)
    {
        $channelRelayDay = $this->channelRelayDayRepository->findWithoutFail($id);

        if (empty($channelRelayDay)) {
            Flash::error(trans('flash.controller.not_found', ['model' => 'Channel Relay Day']));

            return redirect(route('channelRelayDays.index'));
        }

        $channelRelayDay = $this->channelRelayDayRepository->update($request->all(), $id);

        Flash::success(trans('flash.controller.update_success', ['model' => 'Channel Relay Day']));

        return redirect(route('channelRelayDays.index'));
    }

    /**
     * Remove the specified ChannelRelayDay from storage.
     *
     * @param  int $id
     *
     * @return Response
     */
    public function destroy($id)
    {
        $channelRelayDay = $this->channelRelayDayRepository->findWithoutFail($id);

        if (empty($channelRelayDay)) {
            Flash::error(trans('flash.controller.not_found', ['model' => 'Channel Relay Day']));

            return redirect(route('channelRelayDays.index'));
        }

        $this->channelRelayDayRepository->delete($id);

        Flash::success(trans('flash.controller.delete_success', ['model' => 'Channel Relay Day']));

        return redirect(route('channelRelayDays.index'));
    }
}
